# encoding: utf-8
from rest_framework import serializers

from apps.ynauth.serializers import UserSerializer
from .models import Article, ArticleCategory, Comment, Banner


class ArticleCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = ArticleCategory
        fields = ('id', 'name')


class ArticleSerializer(serializers.ModelSerializer):
    category = ArticleCategorySerializer()
    author = UserSerializer()

    class Meta:
        model = Article
        fields = ('id', 'title', 'desc', 'thumbnail', 'pub_time', 'category', 'author')


class CommentSerializer(serializers.ModelSerializer):
    author = UserSerializer()
    reply_to = UserSerializer()

    class Meta:
        model = Comment
        fields = ('id', 'content', 'author', 'pub_time', 'reply_to')

class BannersListSerializer(serializers.ModelSerializer):

    class Meta:
        model = Banner
        fields = ('id','image_url','priority','link_to')
